package com.corddt.service;

import com.corddt.dao.UserMapper;
import com.corddt.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 名称:UserService
 * 描述:
 *
 * @version 1.0
 * @author:corddt
 * @datatime:2024-05-09 16:46
 */
@Service
@Slf4j
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public void register(User user) {
        log.info("Inserting user into database: {}", user);
        userMapper.insertUser(user);
    }

    public User login(String username, String password) {
        log.info("Querying user by username: {}", username);
        User user = userMapper.selectUserByUsername(username);
        if (user != null && user.getPassword().equals(password)) {
            log.info("User authentication successful: {}", user);
            return user;
        }
        log.warn("User authentication failed for username: {}", username);
        return null;
    }
}
